Skip to content

Conversation

@tt-a1i
Copy link
Contributor

@tt-a1i tt-a1i commented Dec 12, 2025

Summary

  • Fix array fields with mode="array" incorrectly re-rendering when a property on any array element is mutated
  • This was a regression introduced in v1.27.0 by the React Compiler compatibility changes (Fix react compiler #1893)

Problem

As reported in #1925, starting from v1.27.0, when working with a form.Field that uses mode="array", when any child Field under the array Field is changed, the entire array Field re-renders.

Root Cause

In the React Compiler fix (#1893), a new reactiveStateValue subscription was added:

const reactiveStateValue = useStore(fieldApi.store, (state) => state.value)

This subscribes to the entire state.value. For array fields, when any child property changes, the array reference changes, causing reactiveStateValue to change, which triggers extendedFieldApi recreation and component re-render.

Solution

Make the reactiveStateValue subscription aware of mode:

const reactiveStateValue = useStore(
  fieldApi.store,
  (opts.mode === 'array'
    ? (state) => Object.keys((state.value as unknown) ?? []).length
    : (state) => state.value) as (state: typeof fieldApi.state) => TData | number,
)

For mode="array":

  • reactiveStateValue now tracks only the array length
  • The state.value getter returns the actual value from fieldApi.state.value
  • This ensures re-renders only occur when items are added/removed, not when properties change

Test Plan

  • Added test case: should not rerender array field when child field value changes
  • All existing tests pass (79 tests in react-form, 403 tests in form-core)

Fixes #1925

…anges

Array fields with `mode="array"` were incorrectly re-rendering when a
property on any array element was mutated. This was a regression
introduced in v1.27.0 by the React Compiler compatibility changes.

The root cause was that `reactiveStateValue` subscribed to the entire
`state.value`, which changes whenever any child property changes.
For array mode, this subscription now only tracks the array length,
ensuring re-renders only occur when items are added or removed.

- Modified `reactiveStateValue` to use array length selector for array mode
- Updated `state.value` getter to return actual value from `fieldApi.state.value`
- Removed redundant `useStore` subscription for array mode
- Added test case to verify array field doesn't re-render on child changes

Fixes TanStack#1925
@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 63f5615

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/react-form Patch
@tanstack/react-form-nextjs Patch
@tanstack/react-form-remix Patch
@tanstack/react-form-start Patch
@tanstack/form-core Patch
@tanstack/angular-form Patch
@tanstack/vue-form Patch
@tanstack/solid-form Patch
@tanstack/svelte-form Patch
@tanstack/form-devtools Patch
@tanstack/lit-form Patch
@tanstack/react-form-devtools Patch
@tanstack/solid-form-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@crutchcorn crutchcorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense to me! Thank you for this!

@nx-cloud
Copy link

nx-cloud bot commented Dec 15, 2025

View your CI Pipeline Execution ↗ for commit 63f5615

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 16s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 13s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-15 11:47:06 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 15, 2025

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1930

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1930

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@1930

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1930

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1930

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@1930

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@1930

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@1930

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@1930

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1930

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@1930

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1930

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1930

commit: 63f5615

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.11%. Comparing base (6892ed0) to head (63f5615).
⚠️ Report is 98 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1930       +/-   ##
===========================================
- Coverage   90.35%   54.11%   -36.25%     
===========================================
  Files          38       18       -20     
  Lines        1752      231     -1521     
  Branches      444       34      -410     
===========================================
- Hits         1583      125     -1458     
+ Misses        149       94       -55     
+ Partials       20       12        -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@crutchcorn crutchcorn merged commit 35921c9 into TanStack:main Dec 15, 2025
6 of 7 checks passed
@github-actions github-actions bot mentioned this pull request Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entire array Field rerenders when a property on any array element is mutated (regression in 1.27.0)

2 participants